package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.hfb.RequestHelper;
import com.atguigu.srb.core.pojo.entity.LendItem;
import com.atguigu.srb.core.pojo.vo.InvestVO;
import com.atguigu.srb.core.service.LendItemService;
import com.atguigu.srb.core.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 标的出借记录表 前端控制器
 * </p>
 *
 * @author lsyandwh
 * @since 2022-12-02
 */
@RestController
@RequestMapping("/api/core/lendItem")
public class ApiLendItemController {

    @Autowired
    private LendItemService lendItemService;

    @PostMapping("/commitInvest")
    public Result commitInvest(@RequestBody InvestVO investVO, HttpServletRequest request){

        String userId = request.getHeader("userId");
        String from = lendItemService.commitInvest(investVO,userId);

        return Result.ok().data("formStr",from);
    }

    @PostMapping("/notify")
    public String lendItemNotify(HttpServletRequest request){

        //获取请求头中所有参数
        Map<String, Object> paramMap = RequestHelper.switchMap(request.getParameterMap());

        lendItemService.lendItemNotify(paramMap);

        return "success";
    }

}

